home *** CD-ROM | disk | FTP | other *** search
- /*
- * voice.c - the talking bore who knows what's wrong with anything.
- *
- * Each sentence is of the following form:
- * The <truthadj> <probnoun> is the <badadj> <badnoun> .
- */
-
- #include <memory.h>
- #include <quickdraw.h>
- #include <window.h>
- #include <osutil.h>
-
- #include "critic.h"
- #include "speech.h"
-
- extern char *truthadj[]; /* a truth adjective */
- extern char *probnoun[]; /* a problem noun */
- extern char *badadj[]; /* derogatory adjectives */
- extern char *badnoun[]; /* derogatory nouns */
-
- int tasize; /* number of elements in truthadj[] */
- int pnsize; /* number of elements in probnoun[] */
- int basize; /* number of elements in badadj[] */
- int bnsize; /* number of elements in badnoun[] */
-
- SpeechHandle theSpeech; /* connection to the speech driver (0 == no driver) */
- #define STATLEN 400 /* max # of chars in a statement */
- SpeechErr err; /* error from speech routines */
-
- /*
- * voice_init() - fire up the voice.
- */
-
- voice_init()
- {
- if ((err = SpeechOn(noReader, &theSpeech))) {
- theSpeech = (Handle) 0;
- voicedfl();
- return;
- }
- voicedfl();
- }
-
- /*
- * voice_stop() - close down the voice.
- */
-
- voice_stop()
- {
- if (!theSpeech) return;
-
- SpeechOff(theSpeech);
- }
-
- /*
- * voiceset() - set the speech driver parameters
- * from the given items and values.
- */
-
- voiceset(gen, infl, pit, rat)
- Sex gen; /* selected gender */
- FOMode infl; /* selected inflection */
- int pit; /* pitch (hz) */
- int rat; /* speaking rate (wpm) */
- {
- if (!theSpeech) return;
-
- SpeechSex(theSpeech, gen);
- SpeechPitch(theSpeech, pit, infl);
- SpeechRate(theSpeech, rat);
- }
-
- /*
- * criticize() - make one critical statement.
- * "The <truthadj> <probnoun> is the <badadj> <badnoun> ."
- */
-
- criticize()
- {
- char *tradjp; /* points to the chosen truth adjective */
- char *prnounp; /* " " problem noun */
- char *bdadjp; /* " " bad adjective */
- char *bdnounp; /* " " bad noun */
- static int first = 1; /* "it's the first call" */
- static Handle statement; /* phonetic sentence to speak */
-
- if (!theSpeech) return;
-
- /*
- * If this is the first call, init the structures
- */
-
- if (first) {
- first = 0;
-
- statement = NewHandle((Size) STATLEN);
- for (tasize = 0; truthadj[tasize]; ++tasize)
- ;
- for (pnsize = 0; probnoun[pnsize]; ++pnsize)
- ;
- for (basize = 0; badadj[basize]; ++basize)
- ;
- for (bnsize = 0; badnoun[bnsize]; ++bnsize)
- ;
- }
-
- tradjp = truthadj[randint(tasize)];
- prnounp = probnoun[randint(pnsize)];
- bdadjp = badadj[randint(basize)];
- bdnounp = badnoun[randint(bnsize)];
-
- HLock(statement);
- strcpy((char *) *statement, vowel(tradjp) ? "DHIY " : "DHAH ");
- strcat((char *) *statement, tradjp);
- strcat((char *) *statement, " ");
- strcat((char *) *statement, prnounp);
- strcat((char *) *statement, " IHZ ");
- strcat((char *) *statement, vowel(bdadjp) ? "DHIY " : "DHAH ");
- strcat((char *) *statement, bdadjp);
- strcat((char *) *statement, " ");
- strcat((char *) *statement, bdnounp);
- strcat((char *) *statement, ".#");
- HUnlock(statement);
-
- if ((err = MacinTalk(theSpeech, statement))) {
- return;
- }
- }
-
- /*
- * vowel() - returns true if the given phonetically-encoded word
- * starts with a vowel.
- */
-
- int
- vowel(word)
- char *word; /* a phonetic string suitable for MacinTalk */
- {
- return(*word == 'A' ||
- *word == 'E' ||
- *word == 'I' ||
- *word == 'O' ||
- *word == 'U');
- }
-
- /*
- * randint() - return a random integer in the range 0 through range - 1.
- */
- int
- randint(range)
- int range;
- {
- static int firsttime = 1;/* True if the first time this has been called */
- long secs; /* value returned from GetDateTime() */
-
- if (firsttime) {
- firsttime = 0;
- GetDateTime(&secs);
- randSeed = secs;
- }
- return((unsigned) Random() % range);
- }
-